<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: anguolei@clcw.com.cn                                           |
// +------------------------------------------------------------------------+
//
namespace AuctionAppApi\Controller;

use AuctionCore\System\AuctionException;
use AuctionCore\Other\Inbox;

/**
 * 消息接口
 */
class InboxController extends BaseController
{

    public function __construct()
    {
        parent::__construct();
    }

    //获取消息列表
    public function get_list()
    {
        $page = I('post.page/d',1);
        $page_size = I('post.page_size/d',20);
        $uid = I('post.uid/d');
        $type = I('post.type/d',0);
        $is_read = I('post.is_read/d',-1);
        if($uid<1){
            AuctionException::make_throw('1000001');
        }
        $params = array(
            'uid' => $uid,
            'type' => $type,
            'is_read' => $is_read
        );
        $result = Inbox::getList($page, $page_size, $params);
        $this->api_200($result);
    }

    //获取新消息数目
    public function get_new_num()
    {
        $uid = I('post.uid/d',0);
        if($uid<1){
            AuctionException::make_throw('1000001');
        }
        $num = Inbox::getUnreadCount($uid);
        $this->api_200($num);
    }

    //查看消息详情
    public function get_msg_detail()
    {
        $uid = I('post.uid/d',0);
        if($uid<1){
            AuctionException::make_throw('1000001');
        }
        $message_id = I('post.message_id');
        $res = Inbox::make_as_read($message_id);
        $detail = Inbox::getDetailById($message_id);
        if(!$detail){
            AuctionException::make_throw('1100002');
        }
        $this->api_200($detail);
    }

}